package com.bhf.config;

import org.elasticsearch.client.RestHighLevelClient;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.elasticsearch.client.ClientConfiguration;
import org.springframework.data.elasticsearch.client.RestClients;
import org.springframework.data.elasticsearch.config.AbstractElasticsearchConfiguration;
import java.time.Duration;

/**
 * @author pwq
 */
@Configuration
public class ElasticsearchConfig extends AbstractElasticsearchConfiguration {

    @Override
    @Bean
    public RestHighLevelClient elasticsearchClient() {
        ClientConfiguration clientConfiguration = ClientConfiguration.builder()
                .connectedTo("192.168.45.131:9200")
                .withHttpClientConfigurer(clientBuilder -> {
                    clientBuilder.setMaxConnTotal(3000);
                    clientBuilder.setMaxConnPerRoute(15);
                    return clientBuilder;
                })
                .withBasicAuth("", "")
                .withConnectTimeout(Duration.ofSeconds(5))
                .build();
        return RestClients.create(clientConfiguration).rest();
    }
}
